package org.stvd.repository.admin.impl;

import org.springframework.stereotype.Repository;
import org.stvd.core.util.StringUtil;
import org.stvd.entities.admin.UserGuid;
import org.stvd.repository.admin.UserGuidDao;
import org.stvd.repository.base.impl.BaseDaoImpl;

@Repository("UserGuidDao")
public class UserGuidDaoImpl extends BaseDaoImpl<UserGuid> implements UserGuidDao{

	@Override
	public void insert(String userId, String[] guids) {
		em.createQuery("delete from UserGuid where userId = :userId")
        .setParameter("userId", userId)
        .executeUpdate();
        em.flush();
        if (guids != null) {
            for (String guid : guids) {
                UserGuid userGuid = new UserGuid();
                userGuid.setId(StringUtil.getRandomUUID());
                userGuid.setUserId(userId);
                userGuid.setGuid(guid);
                insert(userGuid);
            }
        }
	}

	@Override
	public void insert(String userId, String guid) {
		UserGuid userGuid = new UserGuid();
        userGuid.setId(StringUtil.getRandomUUID());
        userGuid.setUserId(userId);
        userGuid.setGuid(guid);
        insert(userGuid);
	}

}
